package com.ssy.lingxi.product.entity.platform;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import lombok.Getter;
import lombok.Setter;

import javax.persistence.*;
import java.io.Serializable;
import java.util.List;

/**
 * 属性实体类--平台后台
 * @author jw.chen
 * @version 2.0.0
 * @date 2020/6/23
 */
@Getter
@Setter
@Entity
@Table(schema = "public", name = "product_attribute", indexes = {@Index(name = "product_attribute_name_idx", columnList = "name"),
        @Index(name = "product_attribute_group_id_idx", columnList = "groupId"),
        @Index(name = "product_attribute_type_idx", columnList = "type"),
        @Index(name = "product_attribute_is_enable_idx", columnList = "isEnable"),
        @Index(name = "product_attribute_is_price_idx", columnList = "isPrice")})
public class Attribute implements Serializable {
    private static final long serialVersionUID = 2954862181520866730L;
    /**
     * 主键id
     */
    @Id
    @GeneratedValue(strategy= GenerationType.SEQUENCE, generator="attribute_seq")
    @SequenceGenerator(sequenceName="product_attribute_seq", name="attribute_seq",allocationSize = 1)
    private Long id;

    /**
     * 属性组id(前端页面不需要传)
     */
    @Column(columnDefinition = "int8", nullable = false)
    private Long groupId;

    /**
     * 属性组名
     */
    @Column(columnDefinition = "varchar(20)", nullable = false)
    private String groupName;

    /**
     * 属性名称
     */
    @Column(columnDefinition = "varchar(20)", nullable = false)
    private String name;

    /**
     * 属性方式：1-单选、2-多选、3-输入
     */
    @Column(columnDefinition = "int", nullable = false)
    private Integer type;

    /**
     * 是否有效属性
     */
    @Column(columnDefinition = "boolean", nullable = false)
    private Boolean isEnable = true;

    /**
     * 是否必填属性
     */
    @Column(columnDefinition = "boolean", nullable = false)
    private Boolean isEmpty;

    /**
     * 是否价格属性
     */
    @Column(columnDefinition = "boolean", nullable = false)
    private Boolean isPrice;

    /**
     * 是否搜索属性
     */
    @Column(columnDefinition = "boolean", nullable = false)
    private Boolean isSearch;

    /**
     * 是否日期属性
     */
    @Column(columnDefinition = "boolean")
    private Boolean isDate = false;

    /**
     * 是否地区属性
     */
    @Column(columnDefinition = "boolean")
    private Boolean isArea = false;

    /**
     * 创建时间
     */
    @Column(columnDefinition = "int8", nullable = false)
    private Long createTime = System.currentTimeMillis();

    /**
     * 属性对应的属性值列表
     */
    @JsonManagedReference
    @OneToMany(mappedBy = "attribute", cascade = CascadeType.ALL)
    private List<AttributeValue> attributeValueList;

    /**
     * 属性对应的品类列表
     */
    @JsonIgnore
    @ManyToMany(mappedBy = "attributeList")
    private List<Category> categoryList;

    /**
     * 排序
     */
    @Transient
    private Integer sort;
}
